﻿using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CefSharp.MinimalExample.WinForms
{
    class CefSettingInit
    {
        public const string CefLibName = @"Module\CefsharpLib"; //cef目录名称
        /// <summary>
        /// 初始化CEF的配置
        /// </summary>
        public static void InitializeCefSetting(string appPath)
        {

            CefSettings settings = new CefSettings
            {
                //Locale = "zh-CN", //中文
                BrowserSubprocessPath = Path.Combine(appPath, CefLibName, "CefSharp.BrowserSubprocess.exe"), //设置浏览器子程序启动路径
                ResourcesDirPath = Path.Combine(appPath, CefLibName),
                //LocalesDirPath = Path.Combine(appPath, CefLibName, @"locales\"),

                //LogFile = "CefGlue.log",
            };
            
            settings.MultiThreadedMessageLoop = true;
            settings.CefCommandLineArgs.Add("--disable-web-security", "");
            settings.CefCommandLineArgs.Add("--user-data-dir", "C:\\MyChromeDevUserData");

            settings.CefCommandLineArgs.Add("no-proxy-server", "1");
            settings.CefCommandLineArgs.Add("disable-gpu", "1");
            //安全证书
            settings.CefCommandLineArgs.Add("--ignore-urlfetcher-cert-requests", "1");
            settings.CefCommandLineArgs.Add("--ignore-certificate-errors", "1");
            //flash
            settings.CefCommandLineArgs.Add("ppapi-flash-path", AppDomain.CurrentDomain.BaseDirectory + "\\Plugins\\pepflash\\pepflashplayer.dll");
            settings.Locale = "zh-CN";
            settings.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
            Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
        }
    }
}
